package com.ktjy.aop;

import org.aspectj.lang.JoinPoint;

import java.util.Arrays;

public class LogManager {

    public void printLog() {
        System.out.println("日志输入....");
    }

    /**
     * 前置增强
     */
    public void before(JoinPoint joinPoint) {
        System.out.println("前置增强" + joinPoint.getTarget() + ",调用的方法:" + joinPoint.getSignature().getName()
                + ",参数" + Arrays.toString(joinPoint.getArgs()));
    }

    /**
     * 后置增强
     */
    public void afterReturning(JoinPoint joinPoint, Object result) {
        System.out.println("后置增强:" + joinPoint.getTarget() + ",调用的方法:" + joinPoint.getSignature().getName()
                + ",方法的返回值:" + result);
    }

    /**
     * 最终增强
     */
    public void after(JoinPoint joinPoint) {
        System.out.println("最终增强:" + joinPoint.getTarget() + ",调用的方法:" + joinPoint.getSignature().getName());
    }

    /**
     * 异常增强
     */
    public void afterThrowing(JoinPoint joinPoint, Exception exception) {
        System.out.println("异常增强:" + joinPoint.getTarget() + ",调用的方法:" + joinPoint.getSignature().getName());
        System.out.println(exception.toString());
    }
}
